/*
 * PayResultPresenter.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.shoppingcart.orderresult;

import android.os.Bundle;

import com.yidiandao.business.R;
import com.yidiandao.business.constant.Intents;
import com.yidiandao.business.data.bean.ShareEntity;
import com.yidiandao.business.data.model.IConfirmOrderModel;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.view.SuperLoadingLayout;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

public class OrderResultPresenter implements OrderResultContract.Presenter {

    private OrderResultContract.View mPayResultView;

    private IConfirmOrderModel mConfirmOrderModel;

    private ShareEntity mShareEntity;
    private String mOrderPayId;
    private String mOrderId;

    public OrderResultPresenter(OrderResultContract.View view, IConfirmOrderModel model) {
        mPayResultView = view;
        mConfirmOrderModel = model;

        mPayResultView.setPresenter(this);
    }

    @Override
    public void start() {
    }

    @Override
    public void extraBundle(Bundle bundle) {
        mOrderPayId = bundle.getString(Intents.EXTRA_ORDER_PAY_ID);
        mOrderId = bundle.getString(Intents.EXTRA_ORDER_ID);
    }

    @Override
    public void loadPayResult() {
        mConfirmOrderModel.loadPayResult(
                mOrderPayId,
                mOrderId,
                mPayResultView.getPagerTag(),
                new IConfirmOrderModel.OnPayResultListener() {
                    @Override
                    public void onSuccess(List<DisplayListItem> displayListItems) {
                        mPayResultView.refreshContent(mPayResultView.checkResultObject(displayListItems));
                        mPayResultView.setDisplayListItems(displayListItems);
                    }

                    @Override
                    public void onPayResult(ShareEntity shareData, String payTitle, boolean success) {
                        mShareEntity = shareData;

                        mPayResultView.setTitle(payTitle);
                        mPayResultView.setShareIconVisibility(success);
                    }

                    @Override
                    public void onFailed() {
                        mPayResultView.setTitle(UIUtils.getString(R.string.buy_failed));
                        mPayResultView.refreshContent(SuperLoadingLayout.STATE_ERROR);
                        mPayResultView.setShareIconVisibility(false);
                    }
                });
    }

    public ShareEntity getShareEntity() {
        return mShareEntity;
    }
}
